package com.shujia.spark.util

import org.wltea.analyzer.core.{IKSegmenter, Lexeme}

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object IK {
  def main(args: Array[String]): Unit = {

    val text = "要是明白人，知道应该怎么办,数加学院"
    println(IK.segment(text))
  }

  /**
   * 分词
   *
   * @param text ：中文文本
   * @return 分词结果
   */
  def segment(text: String): List[String] = {
    val sr = new StringReader(text)
    val ik = new IKSegmenter(sr, true)
    val buffer = new ListBuffer[String]
    var lex: Lexeme = ik.next()
    while (lex != null) {
      buffer += lex.getLexemeText
      lex = ik.next()
    }
    buffer.toList
  }
}